/*
https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence/solution/zui-chang-di-zeng-zi-xu-lie-de-ge-shu-by-w12f/
 */
import java.util.Arrays;

public class Solution673 {
    public int findNumberOfLIS(int[] nums) {
        int n=nums.length;
        int[] f=new int[n];
        int[] g=new int[n];
        Arrays.fill(f,1);
        Arrays.fill(g,1);
        int ans=0;
        int max=0;
        for (int i=0;i<n;i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    if (f[i] == f[j] + 1) {
                        g[i] += g[j];
                    } else if (f[i] < f[j] + 1) {
                        g[i] = g[j];
                        f[i] = f[j] + 1;
                    }
                }
            }
            if (max < f[i]) {
                max = f[i];
                ans = g[i];
            } else if (max == f[i]) {
                ans += g[i];
            }
        }
       return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution673().findNumberOfLIS(new int[]{1,2,4,3,5,4,7,2}));
    }
}
